<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">上门护理服务平台</div>
      <el-form ref="login" :model="dataForm" :rules="rules" class="ms-content" label-width="0px">
        <el-form-item prop="username">
          <el-input v-model="dataForm.username" placeholder="用户名" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="dataForm.password" placeholder="密码" prefix-icon="el-icon-lock" show-password
                    @keyup.enter.native="submitForm()"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      dataForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm() {
      // sessionStorage.setItem('loginUser', JSON.stringify({username:'test',nickname:'test'}));
      // this.$router.push('/');
      this.$refs.login.validate((valid) => {
        if (valid) {
          this.$ajax
              .post("/user/login", null, {
                params: this.dataForm,
              })
              .then((res) => {
                this.$router.push("/");
                if (res.msg=="登录成功") {
                  sessionStorage.setItem("loginUser", JSON.stringify(res.data));
                } else {
                  this.$message.error(res.msg);
                }
              });
        }
      });
    },
  },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url(~@/assets/img/login-bg.png);
  background-size: 100%;
  /* background-size: cover; */
}

.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  color: #545454;
  border-bottom: 1px solid #ddd;
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 350px;
  margin: -190px 0 0 -175px;
  border-radius: 5px;
  background: #f2f6fc;
  overflow: hidden;
}

.ms-content {
  padding: 30px 30px;
}

.login-btn {
  text-align: center;
}

.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}

</style>
